<template>
    <Modal
        v-model="showedit"
        title="重复数据"
        :mask-closable="false"
        footer-hide
        :width="80"
        @on-cancel="cancelmodal"
    >
        <Table :columns="columns" :data="data" @on-sort-change="sortchange" :loading="loading">
            <template slot-scope="{ row }" slot="info">
                <span>
                    {{ row.true_name || row.user_name }} {{ row.gender_str }}
                    {{ row.age }}
                </span>
            </template>
            <template slot-scope="{ row }" slot="disease">
                <span>{{ row.child_diseases_name || row.diseases_name }}</span>
            </template>
            <template slot-scope="{ row }" slot="telphone">
                <div v-if="+info.type === 1 || +info.type === 3">
                    <div v-for="(item, index) of row.phone" :key="index">
                        <p v-if="item.status">
                            <font color="#ed4014">
                                {{ item.phone }}
                            </font>
                        </p>
                        <p v-else>
                            {{ item.phone }}
                        </p>
                    </div>
                </div>
                <div v-else>
                    <p v-for="(item, index) of row.phone" :key="index">
                        {{ item.phone }}
                    </p>
                </div>
            </template>
            <template slot-scope="{ row }" slot="weixin">
                <span v-if="+info.type === 2 || +info.type === 3">
                    <font
                        v-if="row.wechat_id === info.wechat_id"
                        color="#ed4014"
                    >
                        {{ row.wechat_id }} </font
                    ><span v-else>{{ row.wechat_id }}</span>
                </span>
                <span v-else>{{ row.wechat_id }}</span>
            </template>
            <template slot-scope="{ row }" slot="douyin">
                <span v-if="+info.type === 4 || +info.type === 3">
                    <font
                        v-if="row.dy_num === info.dy_num"
                        color="#ed4014"
                    >
                        {{ row.dy_num }} </font
                    ><span v-else>{{ row.dy_num }}</span>
                </span>
                <span v-else>{{ row.dy_num }}</span>
            </template>
            <template slot-scope="{ row }" slot="realname">
                <span v-if="+row.patient_data_type===0">{{ row.realname }}</span>
            </template>
            <template slot-scope="{ row }" slot="state">
                <Tag v-if="row.status_name === '失效'" color="blue">{{
                    row.status_name
                }}</Tag>
                <Tag v-else-if="row.status_name === '跟进中'" color="volcano">{{
                    row.status_name
                }}</Tag>
                <Tag v-else-if="row.status_name === '预约'" color="cyan">{{
                    row.status_name
                }}</Tag>
                <Tag v-else-if="row.status_name === '到诊'" color="green">{{
                    row.status_name
                }}</Tag>
                <Tag
                    v-else-if="row.status_name === '已到老患者'"
                    color="orange"
                    >{{ row.status_name }}</Tag
                >
                <Tag v-else-if="row.status_name" color="orange">{{
                    row.status_name
                }}</Tag>
            </template>
            <template slot-scope="{ row,index }" slot="action">
                <a v-if="+row.is_delete === 1" style="color: red;" v-hasC="btnShows" @click="delpatient(row,index)">删除</a>
            </template>
        </Table>
    </Modal>
</template>

<script>
import { patientindexrepeatlist, patientindexdelete } from "@/api/hqapi";
import params from "./params";
export default {
    props: ["btnShows"],
    data() {
        return {
            showedit: false,
            columns: [
                {
                    title: "基本信息",
                    slot: "info",
                    width: 155,
                    fixed: "left",
                },
                {
                    title: "手机号",
                    slot: "telphone",
                    width: 150,
                },
                {
                    title: "微信号",
                    slot: "weixin",
                    width: 140,
                },
                {
                    title: "抖音号",
                    slot: "douyin",
                    width: 140,
                },
                { title: "患者状态", key: "state", slot: "state", width: 100 },
                {
                    title: "归属人",
                    slot: 'realname',
                    width: 155,
                },
                {
                    title: "回访次数",
                    key: "callback_count",
                    width: 120,
                    sortable: "custom",
                },
                {
                    title: "上次回访时间",
                    key: "last_callback_time_str",
                    width: 155,
                    sortable: "custom",
                },
                { title: "病种", slot: "disease", width: 100 },
                { title: "来源", width: 120, key: "source_name" },
                { title: "创建时间", key: "created_at_str", width: 155 },
                {
                    title: "备注",
                    minWidth: 250,
                    key: "remark",
                    ellipsis: true,
                    tooltip: true,
                },
                { title: "操作", width: 80, slot: "action", fixed: "right" },
            ],
            data: [],
            info: {},
            loading: false,
            params: {
                id: "",
                sort_callback_count: 0,
                sort_last_callback_time: 0,
                page: 0,
                pageSize: 0,
            },
        };
    },
    methods: {
        initial(id) {
            this.params.id = id;
            this.params.sort_callback_count = 0;
            this.params.sort_last_callback_time = 0;
            this.askData();
        },
        askData() {
            this.showedit = true;
            this.loading = true
            patientindexrepeatlist(this.params).then((res) => {
                this.info = res.info;
                for (let items of res.list) {
                    items.phone = [];
                    for (let item of items.mobiles) {
                        items.phone.push({ status: false, phone: item });
                    }
                }
                for (let items of res.list) {
                    for (let item of items.phone) {
                        for (let its of res.info.repeat_mobile) {
                            if (item.phone === its) {
                                item.status = true;
                            }
                        }
                    }
                }
                this.data = JSON.parse(JSON.stringify(res.list));
                this.loading = false
            });
        },
        
        delpatient(row,index) {
            this.$Modal.confirm({
                title: "删除确认",
                content: `<p>删除后患者进入回收站，将不在其他列表展示</p>`,
                loading: true,
                onOk: () => {
                    patientindexdelete({ id: row.id }).then(() => {
                        this.$Message.info("删除成功");
                        this.$emit("askData");
                        this.$Modal.remove()
                        this.data.splice(index,1)
                    });
                },
            });
        },
        sortchange(e) {
            if (e.key === "last_callback_time_str") {
                if (e.order === "desc") {
                    this.params.sort_last_callback_time = 2;
                } else if (e.order === "asc") {
                    this.params.sort_last_callback_time = 1;
                } else {
                    this.params.sort_last_callback_time = 0;
                }
                this.params.sort_callback_count = 0;
            } else if (e.key === "callback_count") {
                if (e.order === "desc") {
                    this.params.sort_callback_count = 2;
                } else if (e.order === "asc") {
                    this.params.sort_callback_count = 1;
                } else {
                    this.params.sort_callback_count = 0;
                }
                this.params.sort_last_callback_time = 0;
            }
            this.askData();
        },
        cancelmodal() {
            this.data = [];
        },
    },
};
</script>

<style lang="less" scoped></style>
